import { Ref, ref } from 'vue';
import { INationNameReturn } from '@/api/types';
import {
  reqCaidDisease,
  reqCbidDisease,
  reqCcidDisease,
  reqChrdDisease,
  reqDiseaseCategory,
  reqEpiDisease,
  reqNationName,
} from '@/api/module/datashowCollectionApi';
import { DynamicSelectOption } from '@/components/types';

export const useNationAPi = () => {
  const nation = ref([]) as Ref<DynamicSelectOption[]>;
  reqNationName().then((res) => {
    nation.value = res.data.map((data) => {
      const { id: value, name: label } = data;
      return { value, label };
    });
  });
  return { nation };
};

export const useDisCategoryAPi = () => {
  const disCategory = ref([]) as Ref<DynamicSelectOption[]>;
  reqDiseaseCategory().then((res) => {
    disCategory.value = res.data.disCategory.map((data) => {
      const { id: value, disCategory: label } = data;
      return { value, label };
    });
    disCategory.value = disCategory.value.slice(1);
  });
  return { disCategory };
};

export const useDisNamesAPi = () => {
  const disNames = ref([]) as Ref<DynamicSelectOption[][]>;
  reqCbidDisease().then((res) => {
    disNames.value[2] = res.data['CBIDName'].map((data) => {
      return { value: data, label: data };
    });
  });
  reqCcidDisease().then((res) => {
    disNames.value[3] = res.data['CCAD'].map((data) => {
      return { value: data, label: data };
    });
  });
  reqEpiDisease().then((res) => {
    disNames.value[4] = res.data['EpiDiseaseNames'].map((data) => {
      return { value: data, label: data };
    });
  });
  reqChrdDisease().then((res) => {
    disNames.value[5] = res.data['CHRDName'].map((data) => {
      return { value: data, label: data };
    });
  });
  return { disNames };
};
